USE GESTION2
go

IF OBJECT_ID('dbo.WASP_D0005_CREA_TABLA_TIPO_CAJA_FECHA') IS NOT NULL 
   BEGIN
      DROP PROCEDURE dbo.WASP_D0005_CREA_TABLA_TIPO_CAJA_FECHA 
      IF OBJECT_ID('dbo.WASP_D0005_CREA_TABLA_TIPO_CAJA_FECHA') 
      IS
      NOT NULL 
         PRINT 
         '<<< FAILED DROPPING PROCEDURE dbo.WASP_D0005_CREA_TABLA_TIPO_CAJA_FECHA >>>'
      ELSE
         PRINT 
         '<<< DROPPED PROCEDURE dbo.WASP_D0005_CREA_TABLA_TIPO_CAJA_FECHA >>>' 
   END
go

SET ANSI_NULLS ON
go

SET QUOTED_IDENTIFIER ON
go

CREATE PROCEDURE WASP_D0005_CREA_TABLA_TIPO_CAJA_FECHA 
AS
   SELECT ctnro AS cta,
      Z07369CT1 AS emp,
      Z07374CON AS feccon,
      Z07351COD AS caja,
      Z07352COD AS tipo 
   INTO dbo.mt_tipo_caja_fecha 
   FROM fsd008, z07369 LEFT OUTER JOIN z07374 ON Z07369CT2 = Z07374CT2 
   AND Z07369CT1 = Z07374CT1 
   WHERE ctccli IN (3, 4, 5) 
   AND ctnro = Z07369CT2 
   ORDER BY ctnro 
--select ctnro as cta, Z07369CT1 as emp, Z07374CON as feccon, Z07351COD as caja, Z07352COD as tipo into dbo.mt_tipo_caja_fecha from fsd008, z07374, z07369 where ctccli in (3,4,5) and ctnro = Z07369CT2 and (Z07369CT2 *= Z07374CT2 and Z07369CT1 *= Z07374CT1 ) order by ctnro

go



SET ANSI_NULLS OFF
go

SET QUOTED_IDENTIFIER OFF
go

IF OBJECT_ID('dbo.WASP_D0005_CREA_TABLA_TIPO_CAJA_FECHA') IS NOT NULL 
   PRINT '<<< CREATED PROCEDURE dbo.WASP_D0005_CREA_TABLA_TIPO_CAJA_FECHA >>>' 
ELSE
   PRINT 
   '<<< FAILED CREATING PROCEDURE dbo.WASP_D0005_CREA_TABLA_TIPO_CAJA_FECHA >>>'
go
